package thread;

public class Demo25 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
            System.out.println("t1 开始");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1 结束");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2 开始");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t2 结束");
        });

        Thread t3 = new Thread(() -> {
            System.out.println("开始解锁");
            synchronized (locker) {
//                locker.notify(); // 这个是随机解锁一个
//                locker.notify();
                locker.notifyAll();
//                locker2.notify(); //通过指定的对象就可以通知对应的线程 notify 必须在对应锁下才可以
                System.out.println("解锁结束");
            }
        });
        t1.start();
        t2.start();
        Thread.sleep(100);
        t3.start();
    }
}
